package mashuaiproject.mashuaiproject.mapper;

import mashuaiproject.mashuaiproject.model.GuanZhu;
import org.apache.ibatis.annotations.*;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public interface AttributeMappper {

    @Insert("insert into guanzhu(user_id,bozhu_id,gmt_create)values(#{user_id},#{bozhu_id},#{gmt_create})")
    int insertNewGuanZhu(GuanZhu guanZhu);

    @Update("update  users set fensi_count=fensi_count+1 where id=#{id}")
    int updateAddBoZhuFensi(@Param("id")Integer id);
    @Update("update  users set fensi_count=fensi_count-1 where id=#{id}")
    int updateARedsBoZhuFensi(@Param("id") Integer boZhuId);

    @Delete("delete from guanzhu where bozhu_id=#{bozhu_id} and user_id=#{user_id}")
    int delGuanzhu(@Param("user_id") Integer id,@Param("bozhu_id") Integer bozhu_id);

    @Select("select count(1) from guanzhu where user_id=#{user_id} and bozhu_id=#{bozhu_id}")
    Integer checkGuanZhu(@Param("bozhu_id") Integer bozhu_id, @Param("user_id") Integer id);

    @Select("select fensi_count from users where id=#{id}")
    Integer selectFenSiCount(@Param("id") Integer bozhu_id);

    @Select("select fensi_count from users where id=#{id}")
    Integer selectFSCount(@Param("id") Integer bozhu_id);

    @Select("select *from guanzhu where bozhu_id=#{id} limit #{offset},#{size}")
    List<GuanZhu> selectOneGuanzhu(@Param("id") Integer id,@Param("offset")Integer offset,@Param("size") Integer size);

    @Select("select count(1) from guanzhu where user_id=#{id}")
    Integer selectMyGuanzhu(@Param("id") Integer id);

    @Select("select *from guanzhu where user_id=#{user_id} limit #{offset},#{size}")
    List<GuanZhu> selectOneMyGuanzhu(@Param("user_id") Integer id,@Param("offset")Integer offset,@Param("size") Integer size);
}
